package com.lexy.grab.fzlhw;

import java.io.File;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.lexy.util.CommMethod;

public class ExeMain {
	
	
	
	
	
	public static void main(String[] args) {
		
		String filePath = "D://pic";
		
		String Url = "http://www.fzlhw.com/duanpianxiaoshuo/215321/";
		Document document = CommMethod.getDocument(Url);
		
		//System.out.println(document);
		//filePath
		getDocumentAll(document,filePath);
		
		
		
		
	}
	
	
	
	public static void getDocumentAll(Document document , String filePath) {
		
		
		Element selectTitle = document.select("td span strong").get(0);
		String text2 = selectTitle.text();
		CommMethod.createFileDir(filePath+"/"+text2);
		Elements select = document.select("td a ");
		for (Element element : select) {
			String href = element.attr("href").replace("?__refresh__", "");
			String text = element.text();
			String fileDir = filePath+"/"+text2+"/"+text;
			CommMethod.createFileDir(fileDir);
			Document currDocument = CommMethod.getDocument(href);
			Elements select2 = currDocument.select("p a img");
			for (int i = 0; i < select2.size(); i++) {
				System.out.println("正在下载 "+text2+"-"+text+" 第"+i+"张 pic");
				Element element2 = select2.get(i);
				String currUrl = element2.attr("src");
				CommMethod.downLoadFile(currUrl, fileDir+"/"+i+".jpg");
			}
			break;
		}
	}
	
	
	
	
	

}
